﻿#ifndef ALGWORKER_H
#define ALGWORKER_H
#include "Common/common.h"
#include <QObject>
#include "vector"
#include <QTime>

class AlgWorker : public QObject
{
	Q_OBJECT
public:
	explicit AlgWorker(QObject *parent = nullptr);
	~AlgWorker();
	int Direction = 0;
	int result1 = 0;
	int result2 = 0;

	int m_nNGorOK[500];
	int m_nResult = 0;

	int m_nType = 0;   //0 正方形  1长方形  2梯形

	int m_nModel = 1; // 0 自动模式 1 手动模式 不计算数据
	HalconCpp::HTuple ModelID;


	HalconCpp::HTuple hvCCDHandle;
	// 存图
	SW_SaveImg m_swSaveImg;


    // 缺陷算法
	Defect m_defect;
    Defect_Rect m_defectRect;
    Defect_Sector m_defectSector;
    Defect_Side m_defectSide;
    Defect_Fback m_defectFback;
    // 尺寸算法
	Judge_Materiel m_JudgeMateriel;
	Judge_Direction m_judgeDirection;
	Measure_Rect m_measureRect;
	Measure_Trapezoid m_measureTrapezoid;
	Measure_TS m_measureTS;
	Measure_TSS m_measureTSS;
    Measure_Side m_measureSide;
    Measure_Sector m_measureSector;

    Measure_Bullet m_measureBullet;



	HTuple Len;
	HTuple Angle;
	HObject OutImg;


	SW_Alg m_swAlg;

    ALG_PLACE m_algPlace;

	// 检测数据 结构体
    // 尺寸
	M_R_DataA m_dM_R_A;
	M_R_DataB m_dM_R_B;
	M_T_DataA m_dM_T_A;

	M_TS_DataA m_dM_TS_A;

	M_TSS_DataA m_dM_TSS_A;

    M_Se_DataA m_dM_Se_A;

	M_Bullet_DataA m_dM_Bullet_A;

    // 缺陷
    D_R_DataA m_dD_R_DataA;
    D_S_DataA m_dD_S_DataA;

	M_NUMBER m_nAlgNG;
	M_NUMBER m_nAlgOK;



	M_NUMBER m_nAlgUp;
	M_NUMBER m_nAlgDown;

    // 异常计数
    int m_nDefectAbn = 0;
    int m_nRectAbn = 0;

	int m_nAlgDefect = 0;
	int m_nAlgRect = 0;
	int CCDNum = 1;

	int CCD_Alg(HalconCpp::HObject img);


    QString strPath;

    bool AlgSw1 = true;
    bool AlgSw2 = true;
signals:
	void sigCameraResult(int m_nResult);


	void sigSaveImgStart(CameraData m_cImageInfo);

    void sigFrameNum();
	public slots :
	void Initialize();
	void start(CameraData m_cImageInfo);



public:
	void show(HalconCpp::HObject img, HalconCpp::HTuple hv_WindowHandle, int index);

	QString msg;
};

#endif // ALGWORKER_H
